using System.Collections;
using UnityEngine;
using UnityEngine.UI;

public class GameScreen : UIScreen
{
	public delegate void GameScreenAction();

	public Button takeScreenshot;

	private RectTransform ssButtonRect;

	private WaitForEndOfFrame wfef = new WaitForEndOfFrame();

	private WaitForSeconds wfbs = new WaitForSeconds(5f);

	private Vector2 startingPos;

	private Vector2 endPos;

	public GameObject joystick;

	public GameObject boostButton;

	public static event GameScreenAction OnGameScreenOpened;

	public static event GameScreenAction OnGameScreenClosed;

	private void Awake()
	{
		takeScreenshot.onClick.AddListener(delegate
		{
			CaptureScreenshot.instance.TakeScreenshotWithLogo();
			GameManager.Instance.screenshotTaken = true;
			ssButtonRect.anchoredPosition = startingPos;
		});
		ssButtonRect = (RectTransform)takeScreenshot.transform;
		startingPos = ssButtonRect.anchoredPosition;
		endPos = new Vector2(0f, 135f);
	}

	public override void ShowScreen()
	{
		ssButtonRect.anchoredPosition = startingPos;
		GameManager.Instance.screenshotTaken = false;
		if (GameScreen.OnGameScreenOpened != null)
		{
			GameScreen.OnGameScreenOpened();
		}
		StartCoroutine(WaitForButtonMove(endPos, 0.3f));
	}

	private IEnumerator WaitForButtonMove(Vector2 end, float seconds)
	{
		yield return wfbs;
		MoveScreenshotButton(end, seconds);
	}

	public void MoveScreenshotButton(Vector2 end, float seconds)
	{
		StartCoroutine(MoveOverSeconds(end, seconds));
	}

	private IEnumerator MoveOverSeconds(Vector2 end, float seconds)
	{
		float elapsedTime = 0f;
		while (elapsedTime <= seconds)
		{
			ssButtonRect.anchoredPosition = Vector2.Lerp(startingPos, end, elapsedTime / seconds);
			elapsedTime += Time.deltaTime;
			yield return wfef;
		}
		ssButtonRect.anchoredPosition = end;
	}
}
